package com.css.fxfzypg.modules.saresults.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.saresults.entity.DzqhXqhBasicMapEntity;
import com.css.fxfzypg.modules.saresults.param.ApTemporarySaveParam;
import com.css.fxfzypg.modules.saresults.service.XqhResultsService;
import com.css.fxfzypg.modules.saresults.vo.SaResultsHlVo;
import com.css.fxfzypg.modules.saresults.vo.SaResultsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 小区划成果库
 */
@RestController
@RequestMapping("xqhResults")
@Slf4j
public class XqhResultsController {

    @Autowired
    private XqhResultsService xqhResultsService;

    /**
     * 小区划成果目录提交,保存，修改
     * @param saResultsVo
     * @return
     */
    @PostMapping("saveOrUpdateXqhResults")
    public RestResponse saveOrUpdateXqhResults(@RequestBody SaResultsVo saResultsVo) {
        return xqhResultsService.saveOrUpdateXqhResults(saResultsVo);
    }

    /**
     * 小区划成果库目录查询(修改回显)
     *
     * @param projectId
     * @return
     */
    @GetMapping("getXqhResultsById")
    public RestResponse getXqhResultsById(String projectId) {
        return xqhResultsService.getXqhResultsById(projectId);
    }

    /**
     * 小区划成果目录项目信息分页查询
     * @param
     * @return
     */
    @GetMapping("getXqhResultsProject")
    public RestResponse getXqhResultsProject(DzqhXqhBasicMapEntity xqhBasicMapEntity, HttpServletRequest request,String geom) {
        return xqhResultsService.getXqhResultsProject(xqhBasicMapEntity, request,geom);
    }

    /**
     * 小区划成果目录孔位信息分页查询
     *
     * @return
     */
    @GetMapping("getXqhResultsHl")
    public RestResponse getXqhResultsHl(SaResultsHlVo saResultsHlVo, HttpServletRequest request,String geom) {
        return xqhResultsService.getXqhResultsHl(saResultsHlVo, request,geom);
    }

    /**
     * 小区划成果数据导出
     *
     * @return
     */
    @GetMapping("exportExcelXqhResults")
    public void exportExcelXqhResults(HttpServletResponse response, String projectId) {
        xqhResultsService.exportExcelXqhResults(response, projectId);
    }

    /**
     * 根据用户id查询未提交数据
     * @return
     */
    @GetMapping("notSubmitted")
    public RestResponse notSubmitted() {
        return xqhResultsService.notSubmitted();
    }

    /**
     * 查询所有项目
     * @param
     * @return
     */
    @GetMapping("queryAllProject")
    public RestResponse queryAllProject() {
        return xqhResultsService.queryAllProject();
    }

    /**
     * 小区划项目信息删除
     *
     * @param
     * @return
     */
    @GetMapping("deleteXqhResultsProject")
    public RestResponse deleteXqhResultsProject(String projectId,String deleteReason,String reviewComments,String approvalStatus) {
        return xqhResultsService.deleteXqhResultsProject(projectId,deleteReason,reviewComments,approvalStatus);
    }

    /**
     * 新增或修改
     * @param param
     * @return
     */
    @PostMapping("saveOrUpdate")
    public RestResponse saveOrUpdate(@RequestBody ApTemporarySaveParam param){
        try {
            xqhResultsService.saveOrUpdate(param);
            return RestResponse.succeed("成功!");
        } catch (Exception e) {
            log.error("post saveOrUpdate error:{}",e.getMessage(),e);
            return RestResponse.fail("失败!");
        }
    }

}
